
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.apps.battery.analyzer &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.apps.battery.analyzer</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.apps.battery.analyzer</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Analysis classes for batteries</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">defaultdict</span>
<span class="kn">import</span> <span class="nn">math</span>

<span class="kn">import</span> <span class="nn">scipy.constants</span> <span class="k">as</span> <span class="nn">const</span>

<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Element</span><span class="p">,</span> <span class="n">Specie</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Composition</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Anubhav Jain&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2011, The Materials Project&quot;</span>
<span class="n">__credits__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;Shyue Ping Ong&quot;</span><span class="p">,</span> <span class="s2">&quot;Geoffroy Hautier&quot;</span><span class="p">]</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Anubhav Jain&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;ajain@lbl.gov&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Sep 20, 2011&quot;</span>

<span class="n">EV_PER_ATOM_TO_J_PER_MOL</span> <span class="o">=</span> <span class="n">const</span><span class="o">.</span><span class="n">e</span> <span class="o">*</span> <span class="n">const</span><span class="o">.</span><span class="n">N_A</span>
<span class="n">ELECTRON_TO_AMPERE_HOURS</span> <span class="o">=</span> <span class="n">EV_PER_ATOM_TO_J_PER_MOL</span> <span class="o">/</span> <span class="mi">3600</span>


<div class="viewcode-block" id="BatteryAnalyzer"><a class="viewcode-back" href="../../../../pymatgen.apps.battery.analyzer.html#pymatgen.apps.battery.analyzer.BatteryAnalyzer">[docs]</a><span class="k">class</span> <span class="nc">BatteryAnalyzer</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A suite of methods for starting with an oxidized structure and determining its potential as a battery</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">struc_oxid</span><span class="p">,</span> <span class="n">cation</span><span class="o">=</span><span class="s1">&#39;Li&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Pass in a structure for analysis</span>

<span class="sd">        Arguments:</span>
<span class="sd">            struc_oxid: a Structure object; oxidation states *must* be assigned for this structure; disordered</span>
<span class="sd">                structures should be OK</span>
<span class="sd">            cation: a String symbol or Element for the cation. It must be positively charged, but can be 1+/2+/3+ etc.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">struc_oxid</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span> <span class="s1">&#39;oxi_state&#39;</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;BatteryAnalyzer requires oxidation states assigned to structure!&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">struc_oxid</span> <span class="o">=</span> <span class="n">struc_oxid</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">comp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">struc_oxid</span><span class="o">.</span><span class="n">composition</span>  <span class="c1"># shortcut for later</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cation</span><span class="p">,</span> <span class="n">Element</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cation</span> <span class="o">=</span> <span class="n">Element</span><span class="p">(</span><span class="n">cation</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">cation_charge</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation</span><span class="o">.</span><span class="n">max_oxidation_state</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">max_cation_removal</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Maximum number of cation A that can be removed while maintaining charge-balance.</span>

<span class="sd">        Returns:</span>
<span class="sd">            integer amount of cation. Depends on cell size (this is an &#39;extrinsic&#39; function!)</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># how much &#39;spare charge&#39; is left in the redox metals for oxidation?</span>
        <span class="n">oxid_pot</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span>
            <span class="p">[(</span><span class="n">Element</span><span class="p">(</span><span class="n">spec</span><span class="o">.</span><span class="n">symbol</span><span class="p">)</span><span class="o">.</span><span class="n">max_oxidation_state</span> <span class="o">-</span> <span class="n">spec</span><span class="o">.</span><span class="n">oxi_state</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">comp</span><span class="p">[</span><span class="n">spec</span><span class="p">]</span> <span class="k">for</span> <span class="n">spec</span>
             <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">comp</span> <span class="k">if</span> <span class="n">is_redox_active_intercalation</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">spec</span><span class="o">.</span><span class="n">symbol</span><span class="p">))])</span>

        <span class="n">oxid_limit</span> <span class="o">=</span> <span class="n">oxid_pot</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation_charge</span>

        <span class="c1"># the number of A that exist in the structure for removal</span>
        <span class="n">num_cation</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">comp</span><span class="p">[</span><span class="n">Specie</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cation</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation_charge</span><span class="p">)]</span>

        <span class="k">return</span> <span class="nb">min</span><span class="p">(</span><span class="n">oxid_limit</span><span class="p">,</span> <span class="n">num_cation</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">max_cation_insertion</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Maximum number of cation A that can be inserted while maintaining charge-balance.</span>
<span class="sd">        No consideration is given to whether there (geometrically speaking) are Li sites to actually accommodate the</span>
<span class="sd">        extra Li.</span>

<span class="sd">        Returns:</span>
<span class="sd">            integer amount of cation. Depends on cell size (this is an &#39;extrinsic&#39; function!)</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># how much &#39;spare charge&#39; is left in the redox metals for reduction?</span>
        <span class="n">lowest_oxid</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="k">lambda</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;Cu&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">})</span>  <span class="c1"># only Cu can go down to 1+</span>
        <span class="n">oxid_pot</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([(</span><span class="n">spec</span><span class="o">.</span><span class="n">oxi_state</span> <span class="o">-</span> <span class="nb">min</span><span class="p">(</span>
            <span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">Element</span><span class="p">(</span><span class="n">spec</span><span class="o">.</span><span class="n">symbol</span><span class="p">)</span><span class="o">.</span><span class="n">oxidation_states</span> <span class="k">if</span> <span class="n">e</span> <span class="o">&gt;=</span> <span class="n">lowest_oxid</span><span class="p">[</span><span class="n">spec</span><span class="o">.</span><span class="n">symbol</span><span class="p">]))</span> <span class="o">*</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">comp</span><span class="p">[</span><span class="n">spec</span><span class="p">]</span> <span class="k">for</span> <span class="n">spec</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">comp</span> <span class="k">if</span>
                        <span class="n">is_redox_active_intercalation</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">spec</span><span class="o">.</span><span class="n">symbol</span><span class="p">))])</span>

        <span class="k">return</span> <span class="n">oxid_pot</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation_charge</span>

    <span class="k">def</span> <span class="nf">_get_max_cap_ah</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">remove</span><span class="p">,</span> <span class="n">insert</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Give max capacity in mAh for inserting and removing a charged cation</span>
<span class="sd">        This method does not normalize the capacity and intended as a helper method</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">num_cations</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="n">remove</span><span class="p">:</span>
            <span class="n">num_cations</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_cation_removal</span>
        <span class="k">if</span> <span class="n">insert</span><span class="p">:</span>
            <span class="n">num_cations</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_cation_insertion</span>

        <span class="k">return</span> <span class="n">num_cations</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation_charge</span> <span class="o">*</span> <span class="n">ELECTRON_TO_AMPERE_HOURS</span>

<div class="viewcode-block" id="BatteryAnalyzer.get_max_capgrav"><a class="viewcode-back" href="../../../../pymatgen.apps.battery.analyzer.html#pymatgen.apps.battery.analyzer.BatteryAnalyzer.get_max_capgrav">[docs]</a>    <span class="k">def</span> <span class="nf">get_max_capgrav</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">remove</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">insert</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Give max capacity in mAh/g for inserting and removing a charged cation</span>
<span class="sd">        Note that the weight is normalized to the most lithiated state,</span>
<span class="sd">        thus removal of 1 Li from LiFePO4 gives the same capacity as insertion of 1 Li into FePO4.</span>

<span class="sd">        Args:</span>
<span class="sd">            remove: (bool) whether to allow cation removal</span>
<span class="sd">            insert: (bool) whether to allow cation insertion</span>

<span class="sd">        Returns:</span>
<span class="sd">            max grav capacity in mAh/g</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">weight</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">comp</span><span class="o">.</span><span class="n">weight</span>
        <span class="k">if</span> <span class="n">insert</span><span class="p">:</span>
            <span class="n">weight</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_cation_insertion</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation</span><span class="o">.</span><span class="n">atomic_mass</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_max_cap_ah</span><span class="p">(</span><span class="n">remove</span><span class="p">,</span> <span class="n">insert</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">weight</span> <span class="o">/</span> <span class="mi">1000</span><span class="p">)</span></div>

<div class="viewcode-block" id="BatteryAnalyzer.get_max_capvol"><a class="viewcode-back" href="../../../../pymatgen.apps.battery.analyzer.html#pymatgen.apps.battery.analyzer.BatteryAnalyzer.get_max_capvol">[docs]</a>    <span class="k">def</span> <span class="nf">get_max_capvol</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">remove</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">insert</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">volume</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Give max capacity in mAh/cc for inserting and removing a charged cation into base structure.</span>

<span class="sd">        Args:</span>
<span class="sd">            remove: (bool) whether to allow cation removal</span>
<span class="sd">            insert: (bool) whether to allow cation insertion</span>
<span class="sd">            volume: (float) volume to use for normalization (default=volume of initial structure)</span>

<span class="sd">        Returns:</span>
<span class="sd">            max vol capacity in mAh/cc</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">vol</span> <span class="o">=</span> <span class="n">volume</span> <span class="k">if</span> <span class="n">volume</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">struc_oxid</span><span class="o">.</span><span class="n">volume</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_max_cap_ah</span><span class="p">(</span><span class="n">remove</span><span class="p">,</span> <span class="n">insert</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1000</span> <span class="o">*</span> <span class="mf">1E24</span> <span class="o">/</span> <span class="p">(</span><span class="n">vol</span> <span class="o">*</span> <span class="n">const</span><span class="o">.</span><span class="n">N_A</span><span class="p">)</span></div>

<div class="viewcode-block" id="BatteryAnalyzer.get_removals_int_oxid"><a class="viewcode-back" href="../../../../pymatgen.apps.battery.analyzer.html#pymatgen.apps.battery.analyzer.BatteryAnalyzer.get_removals_int_oxid">[docs]</a>    <span class="k">def</span> <span class="nf">get_removals_int_oxid</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a set of delithiation steps, e.g. set([1.0 2.0 4.0]) etc. in order to</span>
<span class="sd">        produce integer oxidation states of the redox metals.</span>
<span class="sd">        If multiple redox metals are present, all combinations of reduction/oxidation are tested.</span>
<span class="sd">        Note that having more than 3 redox metals will likely slow down the algorithm.</span>

<span class="sd">        Examples:</span>
<span class="sd">            LiFePO4 will return [1.0]</span>
<span class="sd">            Li4Fe3Mn1(PO4)4 will return [1.0, 2.0, 3.0, 4.0])</span>
<span class="sd">            Li6V4(PO4)6 will return [4.0, 6.0])  *note that this example is not normalized*</span>

<span class="sd">        Returns:</span>
<span class="sd">            array of integer cation removals. If you double the unit cell, your answers will be twice as large!</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># the elements that can possibly be oxidized</span>
        <span class="n">oxid_els</span> <span class="o">=</span> <span class="p">[</span><span class="n">Element</span><span class="p">(</span><span class="n">spec</span><span class="o">.</span><span class="n">symbol</span><span class="p">)</span> <span class="k">for</span> <span class="n">spec</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">comp</span> <span class="k">if</span>
                    <span class="n">is_redox_active_intercalation</span><span class="p">(</span><span class="n">spec</span><span class="p">)]</span>

        <span class="n">numa</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">oxid_el</span> <span class="ow">in</span> <span class="n">oxid_els</span><span class="p">:</span>
            <span class="n">numa</span> <span class="o">=</span> <span class="n">numa</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_int_removals_helper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">comp</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">oxid_el</span><span class="p">,</span> <span class="n">oxid_els</span><span class="p">,</span> <span class="n">numa</span><span class="p">))</span>

        <span class="c1"># convert from num A in structure to num A removed</span>
        <span class="n">num_cation</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">comp</span><span class="p">[</span><span class="n">Specie</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cation</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation_charge</span><span class="p">)]</span>
        <span class="k">return</span> <span class="nb">set</span><span class="p">([</span><span class="n">num_cation</span> <span class="o">-</span> <span class="n">a</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">numa</span><span class="p">])</span></div>

    <span class="k">def</span> <span class="nf">_get_int_removals_helper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spec_amts_oxi</span><span class="p">,</span> <span class="n">oxid_el</span><span class="p">,</span> <span class="n">oxid_els</span><span class="p">,</span> <span class="n">numa</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This is a helper method for get_removals_int_oxid!</span>

<span class="sd">        Args:</span>
<span class="sd">            spec_amts_oxi - a dict of species to their amounts in the structure</span>
<span class="sd">            oxid_el - the element to oxidize</span>
<span class="sd">            oxid_els - the full list of elements that might be oxidized</span>
<span class="sd">            numa - a running set of numbers of A cation at integer oxidation steps</span>
<span class="sd">        Returns:</span>
<span class="sd">            a set of numbers A; steps for for oxidizing oxid_el first, then the other oxid_els in this list</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># If Mn is the oxid_el, we have a mixture of Mn2+, Mn3+, determine the minimum oxidation state for Mn</span>
        <span class="c1"># this is the state we want to oxidize!</span>
        <span class="n">oxid_old</span> <span class="o">=</span> <span class="nb">min</span><span class="p">([</span><span class="n">spec</span><span class="o">.</span><span class="n">oxi_state</span> <span class="k">for</span> <span class="n">spec</span> <span class="ow">in</span> <span class="n">spec_amts_oxi</span> <span class="k">if</span> <span class="n">spec</span><span class="o">.</span><span class="n">symbol</span> <span class="o">==</span> <span class="n">oxid_el</span><span class="o">.</span><span class="n">symbol</span><span class="p">])</span>
        <span class="n">oxid_new</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">oxid_old</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
        <span class="c1"># if this is not a valid solution, break out of here and don&#39;t add anything to the list</span>
        <span class="k">if</span> <span class="n">oxid_new</span> <span class="o">&gt;</span> <span class="n">oxid_el</span><span class="o">.</span><span class="n">max_oxidation_state</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">numa</span>

        <span class="c1"># update the spec_amts_oxi map to reflect that the oxidation took place</span>
        <span class="n">spec_old</span> <span class="o">=</span> <span class="n">Specie</span><span class="p">(</span><span class="n">oxid_el</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="n">oxid_old</span><span class="p">)</span>
        <span class="n">spec_new</span> <span class="o">=</span> <span class="n">Specie</span><span class="p">(</span><span class="n">oxid_el</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="n">oxid_new</span><span class="p">)</span>
        <span class="n">specamt</span> <span class="o">=</span> <span class="n">spec_amts_oxi</span><span class="p">[</span><span class="n">spec_old</span><span class="p">]</span>
        <span class="n">spec_amts_oxi</span> <span class="o">=</span> <span class="p">{</span><span class="n">sp</span><span class="p">:</span> <span class="n">amt</span> <span class="k">for</span> <span class="n">sp</span><span class="p">,</span> <span class="n">amt</span> <span class="ow">in</span> <span class="n">spec_amts_oxi</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">sp</span> <span class="o">!=</span> <span class="n">spec_old</span><span class="p">}</span>
        <span class="n">spec_amts_oxi</span><span class="p">[</span><span class="n">spec_new</span><span class="p">]</span> <span class="o">=</span> <span class="n">specamt</span>
        <span class="n">spec_amts_oxi</span> <span class="o">=</span> <span class="n">Composition</span><span class="p">(</span><span class="n">spec_amts_oxi</span><span class="p">)</span>

        <span class="c1"># determine the amount of cation A in the structure needed for charge balance and add it to the list</span>
        <span class="n">oxi_noA</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="n">spec</span><span class="o">.</span><span class="n">oxi_state</span> <span class="o">*</span> <span class="n">spec_amts_oxi</span><span class="p">[</span><span class="n">spec</span><span class="p">]</span> <span class="k">for</span> <span class="n">spec</span> <span class="ow">in</span> <span class="n">spec_amts_oxi</span> <span class="k">if</span>
                       <span class="n">spec</span><span class="o">.</span><span class="n">symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation</span><span class="o">.</span><span class="n">symbol</span><span class="p">])</span>
        <span class="n">a</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="n">oxi_noA</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">cation_charge</span><span class="p">)</span>
        <span class="n">numa</span> <span class="o">=</span> <span class="n">numa</span><span class="o">.</span><span class="n">union</span><span class="p">({</span><span class="n">a</span><span class="p">})</span>

        <span class="c1"># recursively try the other oxidation states</span>
        <span class="k">if</span> <span class="n">a</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">numa</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">oxid_el</span> <span class="ow">in</span> <span class="n">oxid_els</span><span class="p">:</span>
                <span class="n">numa</span> <span class="o">=</span> <span class="n">numa</span><span class="o">.</span><span class="n">union</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_get_int_removals_helper</span><span class="p">(</span><span class="n">spec_amts_oxi</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">oxid_el</span><span class="p">,</span> <span class="n">oxid_els</span><span class="p">,</span> <span class="n">numa</span><span class="p">))</span>
            <span class="k">return</span> <span class="n">numa</span></div>


<div class="viewcode-block" id="is_redox_active_intercalation"><a class="viewcode-back" href="../../../../pymatgen.apps.battery.analyzer.html#pymatgen.apps.battery.analyzer.is_redox_active_intercalation">[docs]</a><span class="k">def</span> <span class="nf">is_redox_active_intercalation</span><span class="p">(</span><span class="n">element</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    True if element is redox active and interesting for intercalation materials</span>

<span class="sd">    Args:</span>
<span class="sd">        element: Element object</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">ns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Ti&#39;</span><span class="p">,</span> <span class="s1">&#39;V&#39;</span><span class="p">,</span> <span class="s1">&#39;Cr&#39;</span><span class="p">,</span> <span class="s1">&#39;Mn&#39;</span><span class="p">,</span> <span class="s1">&#39;Fe&#39;</span><span class="p">,</span> <span class="s1">&#39;Co&#39;</span><span class="p">,</span> <span class="s1">&#39;Ni&#39;</span><span class="p">,</span> <span class="s1">&#39;Cu&#39;</span><span class="p">,</span> <span class="s1">&#39;Nb&#39;</span><span class="p">,</span> <span class="s1">&#39;Mo&#39;</span><span class="p">,</span> <span class="s1">&#39;W&#39;</span><span class="p">,</span> <span class="s1">&#39;Sb&#39;</span><span class="p">,</span> <span class="s1">&#39;Sn&#39;</span><span class="p">,</span> <span class="s1">&#39;Bi&#39;</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">element</span><span class="o">.</span><span class="n">symbol</span> <span class="ow">in</span> <span class="n">ns</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.apps.battery.analyzer</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>